/*
2021-10-26 
https://leetcode-cn.com/problems/next-greater-numerically-balanced-number/
*/
class Solution {
public:
    bool check(int a)
    {
        vector<int>cnt(10,0);
        int t=a;
        while(t)
        {
            cnt[t%10]++;
            t/=10;
        }
        while(a)
        {
            if(a%10!=cnt[a%10]) return 0;
            a/=10;
        }
        return 1;
    }

    int nextBeautifulNumber(int n) {
        int res=n+1;
        while(!check(res)) res++;
        return res;
    }
};
